const express = require('express');
const app = require('./app');
const swaggerUi = require('swagger-ui-express');
const swaggerJsdoc = require('swagger-jsdoc');
const swaggerOptions = require('./config/swagger'); // 使用自定义的 Swagger 配置

const PORT = process.env.PORT || 3000;

// 在 Swagger UI 中自动添加请求头
const swaggerDocs = swaggerJsdoc(swaggerOptions);

//app.use(express.static('./dist'))

// 设置 Swagger UI
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocs, {
  requestInterceptor: (req) => {
    const token = window.localStorage.getItem('token'); // 从本地存储获取令牌
    if (token) {
      req.headers.Authorization = `Bearer ${token}`;
    }
    return req;
  },
}));

app.listen(PORT, () => {
  console.log(`服务已在${PORT}端口运行`);
});